<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="theme-color" content="#33474d">
	<title>squid代理加用户认证 | 失落的乐章</title>
	<link rel="stylesheet" href="/css/style.css" />
	
      <link rel="alternate" href="/atom.xml" title="失落的乐章" type="application/atom+xml">
    
</head>

<body>

	<header class="header">
		<nav class="header__nav">
			
				<a href="/archives" class="header__link">Archive</a>
			
				<a href="/tags" class="header__link">Tags</a>
			
				<a href="/atom.xml" class="header__link">RSS</a>
			
		</nav>
		<h1 class="header__title"><a href="/">失落的乐章</a></h1>
		<h2 class="header__subtitle">技术面前，永远都是学生。</h2>
	</header>

	<main>
		<article>
	
		<h1>squid代理加用户认证</h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/Squid/">Squid</a>
			</span>
		
	</div>

	

	
		<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;用authentication helpers添加身份验证</p>
<h2 id="有如下几种认证方式-："><a href="#有如下几种认证方式-：" class="headerlink" title="有如下几种认证方式 ："></a>有如下几种认证方式 ：</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line">=&gt; NCSA: Uses an NCSA-style username and password file.</div><div class="line">=&gt; LDAP: Uses the Lightweight Directory Access Protocol</div><div class="line">=&gt; MSNT: Uses a Windows NT authentication domain.</div><div class="line">=&gt; PAM: Uses the Linux Pluggable Authentication Modules scheme.</div><div class="line">=&gt; SMB: Uses a SMB server like Windows NT or Samba.</div><div class="line">=&gt; getpwam: Uses the old-fashioned Unix password file.</div><div class="line">=&gt; SASL: Uses SALS libraries.</div><div class="line">=&gt; NTLM, Negotiate and Digest authentication</div></pre></td></tr></table></figure>
<h2 id="配置NCSA-认证"><a href="#配置NCSA-认证" class="headerlink" title="配置NCSA 认证"></a>配置NCSA 认证</h2><h3 id="一、创建认证用户名-密码，用htpasswd"><a href="#一、创建认证用户名-密码，用htpasswd" class="headerlink" title="一、创建认证用户名/密码，用htpasswd"></a>一、创建认证用户名/密码，用htpasswd</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">htpasswd /etc/squid/passwd user1</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;输入密码</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">New password:</div><div class="line">Re-type new password:</div></pre></td></tr></table></figure>
<h3 id="二、确定squid是否支持authentication-helper"><a href="#二、确定squid是否支持authentication-helper" class="headerlink" title="二、确定squid是否支持authentication helper"></a>二、确定squid是否支持authentication helper</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;yum 安装的</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">rpm -ql squid | grep ncsa_auth</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;输出：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">/usr/lib64/squid/ncsa_auth</div></pre></td></tr></table></figure>
<h3 id="三、配置SQUID认证"><a href="#三、配置SQUID认证" class="headerlink" title="三、配置SQUID认证"></a>三、配置SQUID认证</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">vi /etc/squid/squid.conf</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;加入验证部分内容：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">auth_param basic program /usr/lib64/squid/ncsa_auth /etc/squid/passwd //定义squid密码文件与ncsa_auth文件位置</div><div class="line">auth_param basic children 15 //认证进程的数量</div><div class="line">auth_param basic realm Squid proxy-caching web server</div><div class="line">auth_param basic credentialsttl 2 hours //认证有效期</div><div class="line">auth_param basic casesensitive off //用户名不区分大小写，可改为ON区分大小写</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;添加 acl 验证用户：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">acl ncsa_users proxy_auth REQUIRED</div><div class="line">http_access allow ncsa_users</div></pre></td></tr></table></figure>
<h3 id="四、重启squid生效"><a href="#四、重启squid生效" class="headerlink" title="四、重启squid生效"></a>四、重启squid生效</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="comment"># /etc/init.d/squid restart</span></div></pre></td></tr></table></figure>

	

	
		<span class="different-posts"><a href="/2017/10/12/Squid/9. squid代理加用户认证/" onclick="window.history.go(-1); return false;">⬅️ Go back </a></span>

	

</article>

	</main>

	<footer class="footer">
	<div class="footer-content">
		
	      <div class="footer__element">
	<p>Hi there, <br />welcome to my Blog glad you found it. Have a look around, will you?</p>
</div>

	    
	      <div class="footer__element">
	<h5>Check out</h5>
	<ul class="footer-links">
		<li class="footer-links__link"><a href="/archives">Archive</a></li>
		
		  <li class="footer-links__link"><a href="/atom.xml">RSS</a></li>
	    
		<li class="footer-links__link"><a href="/about">about page</a></li>
		<li class="footer-links__link"><a href="/tags">Tags</a></li>
		<li class="footer-links__link"><a href="/categories">Categories</a></li>
	</ul>
</div>

	    

		<div class="footer-credit">
			<span>© 2017 失落的乐章 | Powered by <a href="https://hexo.io/">Hexo</a> | Theme <a href="https://github.com/HoverBaum/meilidu-hexo">MeiliDu</a></span>
		</div>

	</div>


</footer>



</body>

</html>
